<!DOCTYPE>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<title>游戏详情</title>
<%@ include file="../common/home_head.jsp"%>
</head>
<body>
	<script type="text/javascript">
$(document).ready(function(){
	$("#nav li").removeClass("active");
	$("#nav>li").eq(2).addClass("active");
});

	
	//更新评论
	function updatePalyComments(uid){
		var comment=$("#comment_update").val();
		var score=$('input:radio[name="evaluate"]:checked').val();
		$.ajax({
			url:getContextPath()+"/game/updateComment",
			data:{evaPid:uid,evaContent:comment,score:score},
			type:"POST",
			success:function(result){
				if(result=="y"){
					alert("更新成功！");
				}else{
					alert("更新失败请稍后重试！");
				}
			}
		});
		
	}
	
	
	
	
	//添加评论
	function addPalyComments(id){
		var comment=$("#comment").val();
		var score=$('input:radio[name="evaluate"]:checked').val();
		$.post(getContextPath()+"/game/addComment",
				{
					evaPId:id,
					evaContent:comment,
					score:score
				},
				function(result){
					if(result.r=="yes"){
						alert("成功");
						
					}else if(result.r=="no"){
						alert("失败");
					}else{
						alert(result.r);
					}
				}
		
		);
		
		
	}
	
	//下载游戏
	function downLoadGame(gid){
		var user='<%=session.getAttribute("login")%>';
		if(user=="null"){
			alert("请先登录");
		}else{
			$.ajax({
				url:getContextPath()+"/user/downLoadPalyGame",
				type:"GET",
				data:{gid:gid},
				success:function(result){
					if(result.r=="yes"){
						alert("成功加入库中,再次点击开始下载");
						downLoad();
					}else if(result.r=="in"){
						downLoad();
						//触发下载的点击事件
						document.getElementById("download").click();
						var file=$("#file").val();
						var filename=file.substr(0,file.lastIndexOf("."));
						$.ajax({
							url:getContextPath()+"/user/delete",
							data:{filename:filename},
							type:"POST"
						});
					}else{
						alert("入库失败");
					}
				}
			});
		}
		
	}
	//设置下载标签的属性
	function downLoad(){
		var file = $("#file").val();
		var gid = $("#gid").val();
		var url=getContextPath()+"/user/download?filename="+file+"&gid="+gid;
		$("#download").attr("href",url);
		$("#download").removeAttr("onClick");
		//$.ajax({
		//	url:getContextPath()+"/user/download",
		//	type:"POST",
		//	data:{filename:file,gid:gid},
		//});
	} 
	
	

</script>





	<!-- banner -->
	<div class="sub-banner">
		<%@ include file="../common/navbar.jsp"%>
	</div>
	<!-- banner end -->

	<c:if test="${!empty game }">
		<!-- breadcrumbs -->
		<div class="agileits_breadcrumbs">
			<div class="container">
				<div class="agileits_breadcrumbs_left">
					<ul>
						<li></li>
					</ul>
				</div>
				<div class="agileits_breadcrumbs_right">
					<h3>${game.palyName }</h3>
				</div>
				<div class="clearfix"></div>
			</div>
		</div>
		<!-- //breadcrumbs -->

		<!-- single -->
		<div class="blog">
			<div class="container">
				<div class="col-md-7 wthree_blog_left">
					<div class="wthree_blog_left_grid">
						<div class="wthree_blog_left_grid_slider">
							<img
								src="${pageContext.request.contextPath }/images/games/${game.palyImg}"
								alt="${game.palyName }" class="img-responsive" />
						</div>
						<h4>${game.palyName }</h4>
						<h3>${game.palyIntroduce }</h3>
						<ul>
							<li><span class="glyphicon glyphicon-user"
								aria-hidden="true"></span>${game.palyDeveloper.devName }<i>|</i></li>
							<li><span class="glyphicon glyphicon-heart"
								aria-hidden="true"></span>${game.palyHot }<i>|</i></li>
							<li><span class="glyphicon glyphicon-edit"
								aria-hidden="true"></span>${game.palyType.typeName }<i>|</i></li>
							<li><span class="glyphicon glyphicon-tag" aria-hidden="true"></span>游戏评分</li>
						</ul>
						<p>
							<c:if test="${empty log }">
								暂无更新信息
							</c:if>
							<c:if test="${!empty log }">
								<i>最近更新</i>
								<c:forEach items="${log }" var="l">
									<fmt:formatDate value="${l.log_date}" pattern="yyyy-MM-dd" />
									<br>
								 		${l.log }
								 	</c:forEach>
							</c:if>

						</p>
					</div>
					<input type="hidden" value="${game.palyFile }" id="file"> <input
						type="hidden" value="${game.palyId }" id="gid">
					<c:if test="${!empty login }">
						<!-- 判断当前登录用户是否已经评论 -->
						<c:if test="${!empty leva }">
							<div class="agileits_reply">
								<h3>修改你的评论</h3>
								<form action="javascript:void(0);" method="post">
									<textarea id="comment_update" name="Message" required="" >${leva.evaContent }</textarea>
									<br> 
									<c:if test="${leva.score==1 }">
										<input name="evaluate" type="radio" value="0"><span
										class="glyphicon glyphicon-thumbs-up" aria-hidden="true">好评</span>
										<input name="evaluate" type="radio" value="1" checked> <span 
										class="glyphicon glyphicon-thumbs-down" aria-hidden="true" >差评</span><br>
									</c:if>
									<c:if test="${leva.score==0 }">
										<input name="evaluate" type="radio" value="0" checked><span
										class="glyphicon glyphicon-thumbs-up" aria-hidden="true">好评</span>
										<input name="evaluate" type="radio" value="1"> <span 
										class="glyphicon glyphicon-thumbs-down" aria-hidden="true" >差评</span><br>
									</c:if>	
									<br> <input type="submit" value="提交"
										onclick="updatePalyComments(${game.palyId},${login.userId })">
								</form>
							</div>
						</c:if>
						<c:if test="${empty leva }">
							<div class="agileits_reply">
								<h3>填写你的评论</h3>
								<form action="javascript:void(0);" method="post">
									<textarea id="comment" name="Message" required=""></textarea>
									<br> <input name="evaluate" type="radio" checked value="0"><span
										class="glyphicon glyphicon-thumbs-up" aria-hidden="true">好评</span>
									<input name="evaluate" type="radio" value="1"> <span
										class="glyphicon glyphicon-thumbs-down" aria-hidden="true">差评</span><br>
									<br> <input type="submit" value="提交"
										onclick="addPalyComments(${game.palyId})">
								</form>
							</div>
						</c:if>
					</c:if>
					<c:if test="${empty login }">
						<div class="agileits_reply">
							<h3>填写你的评论</h3>
							<form action="#" method="post">
								<textarea name="Message">请先登录</textarea>
								<br>
							</form>
						</div>
					</c:if>

				</div>
				<div class="col-md-5 wthree_blog_right">
					<div class="w3ls_search">
						<form action="${pageContext.request.contextPath }/search"
							method="post">
							<input type="text" name="key" placeholder="查找游戏" required="">
							<input type="submit" value=" ">
						</form>
					</div>
					<div class="w3l_categories">
						<h3>游戏评论</h3>

						<c:if test="${!empty eva }">
							<ul>
								<c:forEach items="${eva }" var="e">
									<li>${e.evaContent }<c:if test="${e.score==1 }">
											<span class="glyphicon glyphicon-thumbs-down"
												aria-hidden="true"></span>
										</c:if> <c:if test="${e.score==0 }">
											<span class="glyphicon glyphicon-thumbs-up"
												aria-hidden="true"></span>
										</c:if>
									</li>
								</c:forEach>
							</ul>
							<!-- 
							<h5>
								<a href="#">查看更多</a>
							</h5>
							 -->
						</c:if>
						<c:if test="${empty eva }">
							<h1>暂无评论</h1>
						</c:if>

					</div>

					<div class="w3l_archives">
						<h3>操作</h3>
						<ul>
							<li>10 August 2018</li>
							<li><a id="download" href="javascript:void(0);"
								onclick="downLoadGame(${game.palyId})">下载游戏</a></li>
							<li>资助开发者</li>
						</ul>
					</div>
					<div class="w3agile_flickr_posts">
						<c:if test="${!empty hot }">
							<h3>推荐游戏</h3>
							<c:forEach items="${hot }" var="h" begin="0" end="3">
								<div class="w3agile_flickr_post_left">
									<a
										href="${pageContext.request.contextPath }/getPalyDetail?gid=${h.palyId}"><img
										src="${pageContext.request.contextPath }/images/games/${h.palyImg}"
										alt="${h.palyName}" class="img-responsive"
										style="width: 216px; height: 216px;" /></a>
								</div>
							</c:forEach>
						</c:if>
						<div class="clearfix"></div>
					</div>
				</div>
				<div class="clearfix"></div>
			</div>
		</div>
		<!-- //single -->
	</c:if>




	<%@ include file="../common/footer.jsp"%>
	<%@ include file="../common/loginModal.jsp"%>
</body>
</html>